package com.enlf.config;

import com.enlf.interceptor.LoginInterceptor;
import com.enlf.interceptor.RefreshTokenInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

/**
 * _*_ coding : utf-8 _*_
 *
 * @Time : 2023/9/12 14:25
 * @Author : 计201任思伟
 * @File : MvcConfig
 * @Project : enjoy-life
 */
@Slf4j
@Configuration
public class MvcConfig extends WebMvcConfigurationSupport {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    //新建一个拦截器
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        log.debug("开始自定义拦截器...");
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/shop/**",
                        "/voucher/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/blog/hot",
                        "/user/code",
                        "/user/login",
                        "/admin/login",
                        "/admin/me",
                        "/admin/**"

                ).order(1);
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
